#include <graphics.h>
#include "Sprite.h"
#include "input.h"
#include "UI.h"
#include "SceneManager.h"
#include "AssetManager.h"
#include "Scene.h"
#include "AudioAsset.h"
#include "collision.h"
#include <chrono>
#include <windows.h>
using namespace GameEngine;

//=============== �����������Գ��� ===============
// ����1�����˵�����
class MainMenuScene : public Scene {
public:
    MainMenuScene(const std::string& name) : Scene(name) {}

    void OnCreate() override {
        std::cout << "[" << m_name << "] OnCreate() called" << std::endl;
        // ���ز˵���Դ
    }

    void OnDestroy() override {
        std::cout << "[" << m_name << "] OnDestroy() called" << std::endl;
        // �ͷŲ˵���Դ
    }

    void OnActivate() override {
        std::cout << "[" << m_name << "] OnActivate()" << std::endl;
    }

    void OnDeactivate() override {
        std::cout << "[" << m_name << "] OnDeactivate()" << std::endl;
    }

    void Update(float deltaTime) override {
    }

    void Render() override {
        settextcolor(WHITE);
        outtextxy(100, 100, _T("Main Menu (Press E to start game)"));
    }
};

// ����2����Ϸ����
class GameScene : public Scene {
public:
    GameScene(const std::string& name) : Scene(name) {}

    void OnCreate() override {
        std::cout << "[" << m_name << "] OnCreate() called" << std::endl;
        // ������Ϸ��Դ
    }

    void OnDestroy() override {
        std::cout << "[" << m_name << "] OnDestroy() called" << std::endl;
        // �ͷ���Ϸ��Դ
    }

    void OnActivate() override {
        std::cout << "[" << m_name << "] OnActivate()" << std::endl;
    }

    void OnDeactivate() override {
        std::cout << "[" << m_name << "] OnDeactivate()" << std::endl;
    }

    void Update(float deltaTime) override {
    }

    void Render() override {
        settextcolor(YELLOW);
        outtextxy(100, 100, _T("Game Scene (Press Q to return menu)"));
    }
};

int main() {
    // ��ʼ��ͼ�δ���
    initgraph(640, 480);
    BeginBatchDraw();

    // ��������������
    SceneManager sceneManager;
    InputHandler input;
    // ע�᳡������
    sceneManager.RegisterScene<MainMenuScene>("MainMenu");
    sceneManager.RegisterScene<GameScene>("GameScene");
    // ��ʼ�л������˵�
    BeginBatchDraw();
    sceneManager.SwitchToScene("MainMenu");
    // ��ѭ��
    while (true) {
        cleardevice();
        if (input.isKeyDown('Q')) sceneManager.SwitchToScene("MainMenu");
        if (input.isKeyDown('W')) std::cout << "Yes" << std::endl;
        if (input.isKeyDown('E')) sceneManager.SwitchToScene("GameScene");
        // ���µ�ǰ����
        sceneManager.UpdateCurrentScene(16);

        // ��Ⱦ��ǰ����
        sceneManager.RenderCurrentScene();
        input.update();
        // ˫���彻��
        FlushBatchDraw();
        Sleep(16);
    }

    // ������Դ
    sceneManager.UnloadAllScenes();
    EndBatchDraw();
    closegraph();
    return 0;
}